<template>
	<!-- 物资巡检  -->
	<view class="">

		<view class="mian-table">
			<view class="main-table-title">
				<view class="mian-table-name">
					{{ titleType[bstype] }}
				</view>
			</view>
			<view class="mian-table-content">
				<formItem :formConfig='filterMainCF' :formVal='formValueMain' @searchBaseP='searchBaseP'>
				</formItem>
			</view>
		</view>

		<view class="operation">
			<view class="operation-button border-right" @click="submit">
				提交
			</view>
		</view>

	</view>

</template>
<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import config from '@/common/config.js';
	import formItem from '@/components/form/form_item.vue'
	let _self, ajaxUrl;

	export default {
		computed: mapState(['userInfo', 'baseUrl']),
		data() {
			return {
				config,
				formValueMain: {},
				title: '',
				bstype: 1,
				filterMainCF: [],
				titleType: {
					1: '物资巡检',
					2: '物资使用反馈',
					3: '状态维护',
					4: '物资报废'
				}
			}
		},
		components: {
			formItem
		},
		computed: {
			...mapState(['userInfo', 'checkData']),
			// filterMainCF() {
			// 	return this.config.App.onsiteCFMan.filter(item => {
			// 		return item.IsShow == 1;
			// 	})
			// },
		},
		onNavigationBarButtonTap(e) {
			// this.isShowModal = true;
			// if(e.index==0)
			this.openScanMater();
			// console.log(e);
		},
		onLoad(p) {
			console.log(p);
			_self = this
			this.bstype = p.t
			// query.userId = _self.userInfo.UserId
			// query.account = _self.userInfo.Account
			// query.category = p.dbt;

			/* 	console.log(p.item); */
			let abc = JSON.parse(decodeURIComponent(p.item));
			switch (p.t) {
				case '1':
					abc.INSPCEER = _self.userInfo.REALNAME; // 巡检人
					abc.INSPCETIME = this.$utils.getToDateTime(); // 巡检时间
					abc.ISPECPHOTO = ''; // 巡检图片
					abc.VMEMO = ''; // 巡检说明
					abc.INSPCETYPERange = [{
						id: '0',
						name: '更换'
					}, {
						id: '1',
						name: '维护'
					}]
					abc.INSPCETYPEIndex = 0
					abc.INSPCETYPE = 0
					ajaxUrl = '/api/APPCommon/SaveAU_MATINSPEC'
					this.filterMainCF = this.config.App.onsiteCFMan
					break;
				case '2':
					abc.USEMAN = _self.userInfo.REALNAME;
					abc.BACKTIME = this.$utils.getToDateTime();
					abc.BACKPHOTO = '';
					abc.VMEMO = '';
					ajaxUrl = '/api/APPCommon/SaveAU_USEBACK'
					this.filterMainCF = this.config.App.useBaceCFMan
					break;
				case '3':
					abc.USEMAN = _self.userInfo.REALNAME;
					abc.REGTIME = this.$utils.getToDateTime();
					abc.MATPHOTO = '';
					abc.MATSTATE = '';
					abc.VMEMO = '';
					ajaxUrl = '/api/APPCommon/SaveAU_MATTRACK'
					this.filterMainCF = this.config.App.setStatusCFMan
					break;
				case '4':
					abc.APPLYER = _self.userInfo.REALNAME;
					abc.PK_APPLYER = _self.userInfo.UserId;
					abc.SCRAPTIME = this.$utils.getToDateTime();
					abc.SCRAPSTATE = '1';
					abc.MATSTATE = '';
					abc.VMEMO = '';
					ajaxUrl = '/api/APPCommon/SaveDataScrapApply'
					this.filterMainCF = this.config.App.toVoidCFMan
					break;
				default:
					break;
			}

			abc.BILLFROM = '1';
			abc.BDATAFROM = '1';
			// abc.PK_INSTORE = '';
			_self.formValueMain = abc;
			// console.log(this.filterMainCF );
			// console.log(_self.formValueMain);
			// _self.mainOrder.PK_GROUP = abc.PK_GROUP;
			// ajaxUrl = api.apiPublic.SaveDataMoveApply;

		},

		// 基础数据查询
		searchBaseP(tnt) {
			activeType = tnt.type
			let queryParames = "",
				search_PK_GROUP = '';
			if (activeType == "BD_RACK" && !_self.formValueMain.STORENAME) {
				return _self.$utils.tips("请先选择仓库");
			} else if (activeType == "BD_RACK") {
				queryParames = JSON.stringify({
					PK_STORE: this.formValueMain.PK_STORE
				});
			} else if (activeType == "BA_ORGANIZE") {
				search_PK_GROUP = _self.formValueMain.PK_GROUP
			} else if (activeType == "BD_STORE") {
				search_PK_GROUP = _self.formValueMain.PK_ORG
			}

			let URL = "/pages/public/search?t=" + activeType + "&queryjson=" + queryParames + '&PK_GROUP=' +
				search_PK_GROUP
			uni.navigateTo({
				url: URL
			});

		},

		methods: {
			// 基础数据查询
			searchBaseP(tnt) {
				activeType = tnt.type
				let queryParames = "",
					search_PK_GROUP = '';
				console.log(tnt);
				if (activeType == "BD_RACK" && !_self.formValueMain.STORENAME) {
					return _self.$utils.tips("请先选择仓库");
				} else if (activeType == "BD_RACK") {
					queryParames = JSON.stringify({
						PK_STORE: this.formValueMain.PK_STORE
					});
				} else if (activeType == "BA_ORGANIZE") {
					search_PK_GROUP = _self.formValueMain.PK_GROUP
				} else if (activeType == "BD_STORE") {
					search_PK_GROUP = _self.formValueMain.PK_ORG
				}

				let URL = "/pages/public/search?t=" + activeType + "&queryjson=" + queryParames + '&PK_GROUP=' +
					search_PK_GROUP
				uni.navigateTo({
					url: URL
				});

			},
			submit() {

				let data = this.formValueMain;
				if(this.bstype && !this.formValueMain.PK_EQUIP ){
					return this.$utils.tips('请扫描设备二维码')
				}
				console.log(ajaxUrl , data);
				this.axios({
					url: ajaxUrl,
					data: data,
					isLoading: 1
				}).then(res => {
					this.$utils.tips('提交成功')
					_self.$utils.delayBack();
				})
			},
			// 扫描物资
			openScanMater() {
				let URL = api.apiPublic.ScanCode;
				this.$utils.Scan(URL, item => {

					if (item.PK_STATION && !item.PK_MATERIAL) {
						// console.log('扫码物资', item );
						page = 1
						return _self.getList(item)
					}
					// console.log( 333, item );

					item.ischeck = false;
					item.FACTORYDATE = "";
					item.EXPDATE = "180";
					(item.NNUMSQ = item.NNUM), (item.TOTALNUM = item.TOTALNUM);
					item.NNUM = '';
					item.INSTOCKDATE = utils.getToDay();
					item.STORENAME = "";
					item.PK_STORE = "";
					item.STATIONNAME = "";
					item.PK_STATION = "";
					item.INPHOTO = "";
					(item.OUTPHOTO = ""), (item.VBDEF20 = "");
					item.myindex01 = 0;
					item.myindex02 = 0;
					item.NTAXRATE = "";
					item.PURPOSE = "";
					item.ISSURE = false // 物资是否扫码确认
					item.flagText = '未扫码确认请扫码确认'
					item.PK_MATERIAL = item.PK_MATERIAL || item.BILLNO
					_self.planList = [];
					_self.planList.push(item);
				});
			},
		}
	}
</script>

<style scoped lang="scss">
	.mian-table {
		background-color: #ffffff;
		color: #555555;

		.main-table-title {
			margin-top: 20rpx;
			padding: 30rpx 24rpx;
			border-bottom: 1rpx solid #f1f1f1;

			.mian-table-name {
				font-weight: 800;
				font-size: 32rpx;
				position: relative;
				padding-left: 40rpx;
			}

			.mian-table-name:before {
				content: "";
				width: 10rpx;
				height: 32rpx;
				line-height: 32rpx;
				position: absolute;
				margin: 0 16rpx;
				border-radius: 10rpx;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
				background-color: #1677ff;
			}
		}

		.mian-table-content {
			padding: 0 30rpx;
		}
	}
</style>